import router from '@system.router';
import fetch from '@system.fetch';
import newsList from '../../common/data/newsList.js'
export default {
    data: {
        title: 'World',
        type: 'top',
//        lists: newsList.result.data,
        news: [
            {key: 'top', title: '头条', list: newsList.result.data},
            {key: 'shehui', title: '社会', list: []},
            {key: 'guonei', title: '国内', list: []},
            {key: 'guoji', title: '国际', list: []},
            {key: 'yule', title: '娱乐', list: []},
            {key: 'tiyu', title: '体育', list: []},
            {key: 'junshi', title:  '军事', list: []},
            {key: 'keji', title: '科技', list: []},
            {key: 'caijing', title: '财经', list: []},
            {key: 'shishang', title: '时尚', list: []},
            {key: 'youxi', title: '游戏', list: []},
            {key: 'qiche', title: '汽车', list: []},
            {key: 'jiankang', title: '健康', list: []},
        ],
    },
    goIndex(){
        router.back()
    },
// 未来三天的天气
    getNews(){
        const that = this
        const api = 'http://v.juhe.cn/toutiao/index';
        fetch.fetch({
            uri: api + '?type='+this.type+'&key=6d7ee8d88bd4fb137f5d20ce7066a700',
            method: 'GET',
            responseType: 'json',
            success: res => {
                console.log('8888888: '+JSON.stringify(res))
                if (res.code == 200) {
                    const target = JSON.parse(res.data)
                    // that.lists = target.result.data
                    this.news.forEach(item => {
                        if (item.key == this.type ){
                            item.list = target.result.data
                        }
                    })
                    console.log(3333)
                } else {
                    console.log('查询天气失败')
                }
            }
        })
    },
    change(e) {
        console.log('Tab index: '+ e.index)
        this.type = this.news[e.index].key
        this.getNews()
    },
    clickItem(uk) {
        // 跳转到新闻详情页面
        router.push({
            uri: "pages/newsDetail/newsDetail",
            params: {
                uniquekey: uk
            }
        })
    }
}
